/**
 * @file    main.cpp
 * @date    2014-06-22
 * @author  Vladimir Prokopovich VProkopovich@gmail.com
 * @brief   TimerModule demo program
 */
 
#include "CTimerDispatcher.hpp"
#include "CTrace.hpp"   // Timer`s implementation uses this class to print traces
#include <stdio.h>      // Demo program uses printf to print traces

// forward declarations
void callback1(void* pData);
void callback2(void* pData);
void callback3(void* pData);
void callback4(void* pData);
void callback5(void* pData);

int main()
{
   TRC_LEVEL_SET(TRC_LEVEL_NONE);   // disabling Timer implementations traces
   
   // You could turn on all traces:
   // TRC_LEVEL_SET(TRC_LEVEL_DEBUG);

   CTimerDispatcher::getInstance().startTimer(1000U, 2000U, 0, callback1); // Fire after 1 second. then fire every 2 seconds
   CTimerDispatcher::getInstance().startTimer(0U, 500U, 0, callback2); // Fire every half of a second
   CTimerDispatcher::getInstance().startTimer(250U, 0U, 0, callback3); // Fire once after 250 ms from the start
   CTimerDispatcher::getInstance().startTimer(0U, 3000U, 0, callback4); // Fire every 3 seconds
   CTimerDispatcher::getInstance().startTimer(0U, 1000U, 0, callback5); // Fire every 3 seconds
   
   CTimerDispatcher::getInstance().stopTimer(2);

   // Emulating hardware interrupt in order to check if timers are fired in correct order
   for (;;)
   {
      HwTimerIsr();
   }

   return 0;
}

// A set of callback methods
void callback1(void* pData)
{
   printf("Timer 1 is fired. Data pointer is: %p \n", pData);
}
void callback2(void* pData)
{
   printf("Timer 2 is fired. Data pointer is: %p \n", pData);
}
void callback3(void* pData)
{
   printf("Timer 3 is fired. Data pointer is: %p \n", pData);
}
void callback4(void* pData)
{
   printf("Timer 4 is fired. Data pointer is: %p \n", pData);
}
void callback5(void* pData)
{
   printf("Timer 5 is fired. Data pointer is: %p \n", pData);
}